// pages/checkshow/checkshow.js
Page({

  /**
   * 页面的初始数据
   */
  data: {
    wait:[    
    ],
    pass:[
    ],
    unpass:[
    ],
    isClick:true,
    isPass:true,
    refresh:false,
    // x轴方向的偏移
    x: 0,
    // 当前x的值
    currentX: 0,
    num:''
  },
  toHome:function(){
    wx.switchTab({
      url: '../home/home',
    })
  },
  handleMovableChange: function(e) {
    // this.data.currentX = e.detail.x;
    this.data.currentX = e.detail.x;
  },
     
  handleTouchend: function(e) {
    this.isMove = true;
    if (this.data.currentX < -46) {
      this.data.x = -92;
      this.setData({
      x: this.data.x
      });
    } else {
      this.data.x = 0;
      this.setData({
      x: this.data.x
      });
    }
  },
  delete:function(e){
    let item=e.currentTarget.dataset.num;
    console.log(item)
    let that=this;
    // wx.request({
    //   url:'https://yali.geekwhite.cn:3000/checkdel', 
    //   // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
    //   header:{'Access-Control-Allow-Origin':'*'},
    //   header:{'Access-Control-Allow-Methods':'GET,POST'},
    //   data: {
    //     item
    //    },
    //    method: 'post',
    //    success:res=> {
    //     wx.showModal({
    //       title: '提示',
    //       content: '已删除',
    //       success: function (res) {
    //         if (res.confirm) {//这里是点击了确定以后
    //           console.log('用户点击确定')
    //         } else {//这里是点击了取消以后
    //           console.log('用户点击取消')
    //         } 
    //       }
    //     })
    //     that.onLoad()
    //    },
    // })
    wx.showModal({
      title: '提示',
      content: '是否要删除',
      success: function (res) {
        if (res.confirm) {//这里是点击了确定以后
          wx.request({
            url: 'https://yali.geekwhite.cn:3000/checkdel',
            header:{'Access-Control-Allow-Origin':'*'},
            header:{'Access-Control-Allow-Methods':'GET,POST'},
            method:'post',
            data:{
              // sno:wx.getStorageSync('username'),
              item
            },
      
            success:(res)=>{
              that.setData({
                wait:res.data[1],
                pass:res.data[0],
                unpass:res.data[2],
              })
              // console.log(that.data.info)
            }
          })
        } else {//这里是点击了取消以后
          console.log('用户点击取消')
        } 
      },
      
    })
    that.onLoad()
    
  },
  checkShow:function(e){
    let item=e.currentTarget.dataset.num;
    let click= this.data.isClick;
    if(item==0){
      click=true
    }
    if(item==1){
      click=false;
    }
    this.setData({
        isClick:click
    })
  },
  passShow:function(e){
    let item=e.currentTarget.dataset.num;
    let pass= this.data.isPass;
    
    if(item==10){
      pass=true
    }
    if(item==11){
      pass=false;
    }
    this.setData({
        isPass:pass
    })
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    // console.log(options)
    // this.setData({
    //   refresh=this.options.refresh
    // })
    wx.request({
      url:'https://yali.geekwhite.cn:3000/check', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        num:wx.getStorageSync('username')
       },
       method: 'post',
       success:res=> {
           console.log(res.data[0])
            for(var i=0;i<3;i++){
              res.data[i].map((items)=>{
                let sstr=items.Start+''
                let estr=items.Endtime+''
                if(sstr.length==3){
                  items.Start='0'+sstr.substring(0,sstr.length-2)+':'+sstr.substring(1,sstr.length)
                }
                else{
                  items.Start=sstr.substring(0,sstr.length-2)+':'+sstr.substring(2,sstr.length)

                }
                if(estr.length==3){
                  items.Endtime='0'+estr.substring(0,estr.length-2)+':'+estr.substring(1,estr.length)
                }
                else{
                  items.Endtime=estr.substring(0,estr.length-2)+':'+estr.substring(2,estr.length)
                }
              })
            }
            this.setData({
              wait:res.data[1],
              pass:res.data[0],
              unpass:res.data[2],
            })   
            // console.log(wx.getStorageSync('username'))

       },
    }) 
    // let _this = this;
    // wx.createSelectorQuery().selectAll('.delBtn ').boundingClientRect(function(rect) {
    // _this.data.delWidth = rect[0].width;
    // }).exec();
   },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function (options) {
    wx.request({
      url:'https://yali.geekwhite.cn:3000/check', 
      // header: { 'Content-Type': 'application/x-www-form-urlencoded;charset=utf-8' },
      header:{'Access-Control-Allow-Origin':'*'},
      header:{'Access-Control-Allow-Methods':'GET,POST'},
      data: {
        num:wx.getStorageSync('username')
       },
       method: 'post',
       success:res=> {
           console.log(res.data)
           for(var i=0;i<3;i++){
            res.data[i].map((items)=>{
              let sstr=items.Start+''
              let estr=items.Endtime+''
              if(sstr.length==3){
                items.Start='0'+sstr.substring(0,sstr.length-2)+':'+sstr.substring(1,sstr.length)
              }
              else{
                items.Start=sstr.substring(0,sstr.length-2)+':'+sstr.substring(2,sstr.length)

              }
              if(estr.length==3){
                items.Endtime='0'+estr.substring(0,estr.length-2)+':'+estr.substring(1,estr.length)
              }
              else{
                items.Endtime=estr.substring(0,estr.length-2)+':'+estr.substring(2,estr.length)
              }
            })
          }
            this.setData({
              wait:res.data[1],
              pass:res.data[0],
              unpass:res.data[2],
            })  
          } 
          })
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})